<?php 
 	if (($format == 1) || ($format == 2)) {
		header("Pragma: public");
		header("Expires: 0");
		header("Accept-Ranges: bytes");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		if ($format == 1) {
			header("Content-Type: application/vnd.ms-word");
			header('Content-Disposition: attachment; filename=spisok.doc');
		} else {
			header("Content-Type: application/vnd.ms-excel");
			header('Content-Disposition: attachment; filename=spisok.xls');			
		}
		header("Content-Transfer-Encoding: binary");
	}
?>
<h2><?php __('Поиск по студентам');?></h2>
<table cellpadding="0" cellspacing="0" class='art-article'>
<?php
// debug($courses);
//debug($studentsinfos);
if ($studentsinfos){
	$i = 1;
	echo '
		<tr>
			<th><b>№</b></th>
			<th><b>ID</b></th>
			<th><b>ФИО</b></th>
			<th><b>Пол</b></th>
			<th><b>Дата рождения</b></th>
			<th><b>Адрес</b></th>
			<th><b>Данные док-та о обр.</b></th>
			<th><b>Факультет</b></th>
			<th><b>Тип обучения</b></th>
			<th><b>Состояние</b></th>
			<th><b>Действия</b></th>			
		</tr>
	';
foreach ($studentsinfos as $studentinfo):

?>
	<tr>
		<td>
			<?php echo $i; ?>
		</td>	
		<td>
			<?php echo $studentinfo['Studentinfo']['student_id']; ?>
		</td>
		<td>
			<?php echo $studentinfo['Studentinfo']['lastname']; ?> 
			<?php echo $studentinfo['Studentinfo']['firstname']; ?> 
			<?php echo $studentinfo['Studentinfo']['surname']; ?> 
		</td>
		<td>
			<?php echo $genders[$studentinfo['Studentinfo']['gender_id']]; ?>
		</td>
		<td>
			<?php echo $studentinfo['Studentinfo']['birthdate']; ?>
		</td>
		<td>
			<?php echo $studentinfo['Studentinfo']['passport_adress']; ?>
		</td>		
		<td>
			<?php  echo $educationdoctypes[$studentinfo['Studentinfo']['educationdoctype_id']].'&nbsp;'; 
			echo $studentinfo['Studentinfo']['educationdocdata'];
			?>
		</td>				
		<td>
			<?php foreach ($students as $student):
				if ($studentinfo['Studentinfo']['student_id'] == $student['Student']['id']) {
					foreach($courses as $course):
					if ($course['Course']['id'] ==  $student['Studentgroup']['course_id']) {
						echo $course['Profession']['name'];
						echo ' ';
						echo $course['Course']['name'];
						echo ' ';
						break;
					}
					endforeach;
					echo $student['Studentgroup']['name'];
				}
			endforeach;

			 ?>
		</td>
		<td>
			<?php foreach ($students as $student):
				if ($studentinfo['Studentinfo']['student_id'] == $student['Student']['id']) {
					echo $learningtypes[$student['Student']['learningtype_id']];
					break;
				}
			endforeach;

			 ?>
		</td>
		<td>
			<?php 
			foreach ($students as $student):
			if ($studentinfo['Studentinfo']['student_id'] == $student['Student']['id']) {
				if ($student['Student']['studentstate_id'] == 2 || $student['Student']['studentstate_id']== 3){
					echo '<font color=red>'.$studentstates[$student['Student']['studentstate_id']].'</font>';
				} else {
					echo $studentstates[$student['Student']['studentstate_id']];
				}
				
				break;
			}
			endforeach;
			?>
		</td>
		<td class="actions">
			<?php
			// выводим если отображение простой список в случае если файл не выводим
			if ($format == 0){
				echo $html->link(__('Подробнее', true), array('controller' => 'studentinfos', 'action' => 'showinfo', $studentinfo['Studentinfo']['student_id'])); 
			}
			?>
		</td>
	</tr>
<?php 	$i++;
		endforeach; 
}
else {
	echo '<tr><td>';
	echo '<font color=red>Совпадений не найдено</font>';
	echo '</td></tr>';
}
?>
</table>